using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tKitchen
{
    public partial class RecipeInput : Form
    {
        RecipePresenter presenter;

        #region Properties
        public double Amount
        {
            get { return Double.Parse(textBoxAmount.Text); }
            set { textBoxAmount.Text = value.ToString(); }
        }
        public int UnitId
        {
            get {
                if (comboBoxUnit.SelectedIndex != -1)
                {
                    return (int)comboBoxUnit.SelectedValue;
                }
                else
                {
                    return -1;
                }
            }
            //set { }
        }
        public int IngredientId
        {
            get { return (int)comboBoxIngredient.SelectedValue; }
            //set { }
        }

        public string RecipeName
        {
            get { return textBoxName.Text; }
            set { textBoxName.Text = value; }
        }
        public string RecipeDescr
        {
            get { return textBoxDescr.Text; }
            set { textBoxDescr.Text = value; }
        }

        public ComboBox Categorys
        {
            get { return comboBoxCategory; }
            set { comboBoxCategory = value; }
        }
        public ComboBox Units
        {
            get { return comboBoxUnit; }
            set { comboBoxUnit = value; }
        }

        public ComboBox Ingredients
        {
            get { return comboBoxIngredient; }
            set { comboBoxIngredient = value; }
        }

        public DataGridView Recipe_Ingredients
        {
            get { return dataGridViewIngredients; }
            set { dataGridViewIngredients = value; }
        }

        public string StepDescr
        {
            get { return textBoxStep.Text; }
            set { textBoxStep.Text = value; }
        }

        public DataGridView Steps
        {
            get { return dataGridViewSteps; }
            set { dataGridViewSteps = value; }
        }

        #endregion



        public RecipeInput()
        {
            InitializeComponent();
        }

        


        private void RecipeInput_Load(object sender, EventArgs e)
        {
        }

        #region Events
        public event EventHandler Form_Closed = delegate { };
        public event EventHandler Form_Closing = delegate { };
        public event EventHandler SaveClick = delegate { };
        public event EventHandler AddIngredientButtonClick = delegate { };
        public event EventHandler AddStepButtonClick = delegate { };
        public event EventHandler IngredientEndEdit = delegate { };
        public event EventHandler StepEndEdit = delegate { };


        private void RecipeInput_FormClosed(object sender, FormClosedEventArgs e)
        {
            Form_Closed(sender, e);
        }

        private void RecipeInput_FormClosing(object sender, FormClosingEventArgs e)
        {
            Form_Closing(sender, e);
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            SaveClick(sender, e);
        }

        private void buttonAddIngredient_Click(object sender, EventArgs e)
        {
           
            AddIngredientButtonClick(sender, e);

            textBoxAmount.Clear();
            textBoxAmount.Focus();
            comboBoxIngredient.SelectedIndex = -1;
            comboBoxUnit.SelectedIndex = -1;


        }

        private void buttonAddStep_Click(object sender, EventArgs e)
        {
            AddStepButtonClick(sender, e);

            textBoxStep.Clear();
            textBoxStep.Focus();

            
        }
        private void dataGridViewIngredients_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            IngredientEndEdit(sender, e);

        }
        private void dataGridViewSteps_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            StepEndEdit(sender, e);
        }



        #endregion







        #region to be depricated
        public RecipeInput(RecipePresenter presenterIn)
        {
            InitializeComponent();

            presenter = presenterIn;
        }
        public void SetRecipe_IngredientDataSource(List<Recipe_Ingredient> list)
        {
            throw new WarningException("This function is to be depricated");
            dataGridViewIngredients.DataSource = list;
        }

        internal void RefreshGrids()
        {
            throw new WarningException("This function is to be depricated");
            dataGridViewIngredients.Refresh();
            dataGridViewSteps.Refresh();
        }
        #endregion

        private void dataGridViewIngredients_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

    }
}